package org.dromara.bclt.controller;

import java.util.List;

import lombok.RequiredArgsConstructor;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.log.annotation.Log;
import org.dromara.common.web.core.BaseController;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.core.validate.EditGroup;
import org.dromara.common.log.enums.BusinessType;
import org.dromara.common.excel.utils.ExcelUtil;
import org.dromara.bclt.domain.vo.PusheVo;
import org.dromara.bclt.domain.bo.PusheBo;
import org.dromara.bclt.service.IPusheService;
import org.dromara.common.mybatis.core.page.TableDataInfo;

/**
 * 手环-消息推送
 * 前端访问路由地址为:/bclt/pushe
 *
 * @author YHGao
 * @date 2024-10-21
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/pushe")
public class PusheController extends BaseController {

    private final IPusheService pusheService;

    /**
     * 查询手环-消息推送列表
     */
    @SaCheckPermission("bclt:pushe:list")
    @GetMapping("/list")
    public TableDataInfo<PusheVo> list(PusheBo bo, PageQuery pageQuery) {
        return pusheService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出手环-消息推送列表
     */
    @SaCheckPermission("bclt:pushe:export")
    @Log(title = "手环-消息推送", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PusheBo bo, HttpServletResponse response) {
        List<PusheVo> list = pusheService.queryList(bo);
        ExcelUtil.exportExcel(list, "手环-消息推送", PusheVo.class, response);
    }

    /**
     * 获取手环-消息推送详细信息
     *
     * @param id 主键
     */
    @SaCheckPermission("bclt:pushe:query")
    @GetMapping("/{id}")
    public R<PusheVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long id) {
        return R.ok(pusheService.queryById(id));
    }

    /**
     * 新增手环-消息推送
     */
    @SaCheckPermission("bclt:pushe:add")
    @Log(title = "手环-消息推送", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PusheBo bo) {
        return toAjax(pusheService.insertByBo(bo));
    }

    /**
     * 新增手环-消息推送
     */
    @SaCheckPermission("bclt:pushe:add")
    @Log(title = "手环-消息推送", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping("/addMessage")
    public R<Void> addMessage(@Validated(AddGroup.class) @RequestBody PusheBo bo) {
        return toAjax(pusheService.insertMessageByBo(bo));
    }

    /**
     * 修改手环-消息推送
     */
    @SaCheckPermission("bclt:pushe:edit")
    @Log(title = "手环-消息推送", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PusheBo bo) {
        return toAjax(pusheService.updateByBo(bo));
    }

    /**
     * 删除手环-消息推送
     *
     * @param ids 主键串
     */
    @SaCheckPermission("bclt:pushe:remove")
    @Log(title = "手环-消息推送", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] ids) {
        return toAjax(pusheService.deleteWithValidByIds(List.of(ids), true));
    }
}
